﻿using System;
using System.Collections.Generic;
using Scrips.CharacterBehavior;
using Scrips.PlayerData;
using UnityEngine;

public class PlayerStateManger 
{
    private static PlayerStateManger _instance;

    public static PlayerStateManger instance
    {
        get
        {
            if (_instance==null)
            {
                _instance = new PlayerStateManger();
            }
            
            return _instance;
        }
      
    }
    
    /// <summary>
    /// 方法(object)字典
    /// </summary>
    private Dictionary<PlayerState, PlayerBaseMode> mGamePlayerModeDict;

    /// <summary>
    /// 
    /// </summary>
    public PlayerBaseMode mCurGamePlayerMode;

    public void Init(Player_Cc mPlayer)
    {
        mGamePlayerModeDict = GamePlayerModeConfig.CreatGameModeDict(mPlayer);
        //玩家初始状态 Idle
        ChangePlayerMode(PlayerState.Idle);
    }

    public void UpdateState()
    {
        mCurGamePlayerMode?.Update();
    }
    
    /// <summary>
    /// 切换状态 
    /// </summary>
    /// <param name="mType"></param>
    /// <param name="mParams"></param>
    public void ChangePlayerMode(PlayerState mType, object[] mParams = null)
    {
        //Debug.Log(mType);
        //执行上个状态的结束
        mCurGamePlayerMode?.End();
        
        //切换状态
        mCurGamePlayerMode = mGamePlayerModeDict[mType];

        //执行当前状态的开始
        mCurGamePlayerMode?.Begin(mParams);
    }
}